package com.boot.ch1;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * <pre>
 * 1) @Component和@Configuration作为配置类的区别
 * https://blog.csdn.net/long476964/article/details/80626930
 *
 * 2) @Configuration注解，也会为当前类创建一个bean 实例
 * </pre>
 */
@Configuration
public class MyConfig {

    private AtomicInteger version = new AtomicInteger(0);

    @Bean
    public Driver driver() {
        Driver driver = new Driver();
        driver.setId(1);
        driver.setName("driver");
        driver.setCar(car());
        return driver;
    }

    @Bean
    public Car car() {
        Car car = new Car();
        car.setId(1);
        car.setName("car");
        car.setVersion(version.incrementAndGet());
        return car;
    }
}
